/*
 * Qinlan Shen
 * November 8, 2010
 * Pd. 8
 * 
 * Class representing the boss, Mr. Rose, who can move and keep track of which script he's on
 * 
 */

import java.awt.*;
import java.io.*;
import java.util.*;
import javax.imageio.*;

public class Rose extends Enemy
{
	private int xDest;
	private int yDest;
	private int script;
	private int numScripts;
	private int squareDimension;
	public Rose(Image i, int s, int t, int d)
	{
		img = i;
		hitbox = d/2;
		squareDimension = d;
		x = 320;
		y = d;
		xDest = (int)x;
		yDest = (int)y;
		xSpeed = 0;
		ySpeed = 0;
		script = s;
		numScripts = t;
	}
	
	public int getXDest()
	{
		return xDest;
	}
	
	public int getYDest()
	{
		return yDest;
	}
	
	public int getNumCurrentScript()
	{
		return script;
	}
	
	public int getTotalScripts()
	{
		return numScripts;
	}
	
	//Changes Mr. Rose's position
	public void update()
	{
		if (Math.sqrt(Math.pow(xSpeed, 2) + Math.pow(ySpeed, 2)) > Math.sqrt(Math.pow(xDest - x, 2) + Math.pow(yDest - y, 2)))
		{
			x = xDest;
			y = yDest;
		}
		else if (Math.round(x) != xDest || Math.round(y) != yDest)
		{
			x += xSpeed;
			y += ySpeed;
		}
		else
		{
			xSpeed = 0;
			ySpeed = 0;
		}
	}
	
	//Rose moves to xNew, yNew at speed pixels per frame
	public void moveUsingSpeed(int xNew, int yNew, int speed)
	{
		xDest = xNew;
		yDest = yNew;
		if(x == xNew && y == yNew)
		{
			xSpeed = 0;
			ySpeed = 0;
		}
		else
		{
			double xDiff = xNew - x;
			double yDiff = yNew - y;
			int totalDist = (int) Math.sqrt(Math.pow(xDiff, 2) + Math.pow(yDiff, 2));
			xSpeed = xDiff * speed/totalDist;
			ySpeed = yDiff * speed/totalDist;
		}
	}
	
	//Rose moves to xNew, yNew in frame frames
	public void moveUsingFrames(int xNew, int yNew, int frame)
	{
		xDest = xNew;
		yDest = yNew;
		xSpeed = (xNew - x)/frame;
		ySpeed = (yNew - y)/frame;
	}
	
	//Rose moves to a random location within a box in frames frames
	public void randomMove(int xBox, int yBox, int frames)
	{
		int xNew;
		int yNew;
		do
		{
			xNew = (int) (x + (int)((Math.random()-.5) * 2 * xBox));
			yNew = (int) (y + (int)((Math.random()-.5) * 2 * yBox));
		}
		while (xNew < hitbox * 2 || yNew < hitbox * 2 || xNew > 640 - hitbox || yNew > 820 - hitbox);
		moveUsingFrames(xNew, yNew, frames);
	}
	
	//Changes which script Rose is currently on
	public void incrementScript()
	{
		script++;
	}
}